package test1225;

public class Test02 {
    public static void main(String[] args) {

        int[] arr = {1,2,3,4,5};

        // 返回最大值
        int max = m1(arr);
        System.out.println(max);

        // 返回最小值
        int min = m2(arr);
        System.out.println(min);

        // 返回平均值
        double avg = m3(arr);
        System.out.println(avg);

    }
    public static int m1(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }
    public static int m2(int[] arr) {
        int min = arr[0];
        for (int i=1; i< arr.length; i++){
            if(min >arr[i]){
                min = arr[i];
            }
        }
        return  min;
    }
    public static int m3(int[] arr){
        int avg=arr[0];
        for (int i=1; i< arr.length; i++){
            if(avg>arr[i]){
                avg=arr[i];
            }
        }
        return avg;
    }
}
